﻿<Serializable()>
Public Class ProjectEditor
    Private LinkdProjectValue As L3DObjectsLibrary.Project
    Public Event CloseRequest(ByVal sender As Object, ByVal CloseStatus As Microsoft.VisualBasic.MsgBoxResult)
#Region "PROPERTIES"
    Public Property LinkedProject As L3DObjectsLibrary.Project
        Get
            Return LinkdProjectValue
        End Get
        Set(ByVal value As L3DObjectsLibrary.Project)
            LinkdProjectValue = value
            FillFromLinkedProject()
        End Set
    End Property
#End Region
#Region "METHODS"
    Public Sub FillFromLinkedProject()
        With LinkedProject
            txtName.Text = .Name
            txtHighlights.Text = .ProjectHighlights
            dateSOP.Value = .ProjectSOPDate
            dateDAP.Value = .ProjectDAPDate
            scrlStatus.Value = .ProjectRisk
            chkMilestoneDAP.Checked = .VisibleMilestones.DAP
            chkMilestoneSOP.Checked = .VisibleMilestones.SOP
        End With
    End Sub
    Private Sub ControlsHandlersAdd(ByVal Father As Object)
        For Each Control As Windows.Forms.Control In Father.Controls
            If Control.HasChildren = True Then
                ControlsHandlersAdd(Control)
            End If
            If Control.GetType = GetType(Windows.Forms.TextBox) _
                    Or Control.GetType = GetType(Windows.Forms.DateTimePicker) _
                    Or Control.GetType = GetType(Windows.Forms.ComboBox) _
                    Or Control.GetType = GetType(Windows.Forms.NumericUpDown) _
                    Or Control.GetType = GetType(Windows.Forms.CheckBox) Then
                AddHandler Control.KeyUp, AddressOf Key_UP
            End If
        Next
    End Sub
#End Region
#Region "EVENTS"
    Public Sub Key_UP(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Windows.Forms.Keys.Enter Then
            cmdOK.PerformClick()
        ElseIf e.KeyCode = Windows.Forms.Keys.Escape Then
            cmdCancel.PerformClick()
        End If
    End Sub
    Private Sub scrlStatus_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles scrlStatus.Scroll, scrlStatus.ValueChanged
        Select Case scrlStatus.Value
            Case 1
                pictStatus.Image = My.Resources.greencircle
            Case 2
                pictStatus.Image = My.Resources.yellowtriangle
            Case 3
                pictStatus.Image = My.Resources.redcross
        End Select
    End Sub
    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        RaiseEvent CloseRequest(Me, MsgBoxResult.Ok)
        Dim VisibleMilestones As New VisibleMilestonesStructure
        With VisibleMilestones
            .DAP = chkMilestoneDAP.Checked
            .SOP = chkMilestoneSOP.Checked
        End With
        With LinkdProjectValue
            .Name = txtName.Text
            .ProjectHighlights = txtHighlights.Text
            .ProjectSOPDate = dateSOP.Value
            .ProjectDAPDate = dateDAP.Value
            .ProjectRisk = scrlStatus.Value
            .VisibleMilestones = VisibleMilestones
        End With
    End Sub
    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        RaiseEvent CloseRequest(Me, MsgBoxResult.Cancel)
    End Sub
    Private Sub ProjectEditor_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        BringToFront()
        ControlsHandlersAdd(Me)
    End Sub
    Private Sub ProjectEditor_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim g As System.Drawing.Graphics = e.Graphics
        Dim Rect As New System.Drawing.Rectangle(1, 1, Me.Width - 3, Me.Height - 3)
        Dim MyPen As New System.Drawing.Pen(New System.Drawing.SolidBrush(Drawing.ColorTranslator.FromHtml("#000000")), 1)
        g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
        VMGenLibrary.Graphics.DrawRoundedRectangle(g, MyPen, Rect, New System.Drawing.Size(20, 20), Drawing.ColorTranslator.FromHtml("#FFFFC0"))

    End Sub
#End Region
End Class
